package sskj.regulatory.domain.interactor

import sskj.regulatory.data.pref.Preferences
import okhttp3.Interceptor
import okhttp3.Response
import sskj.regulatory.data.network.ApiConstants

class TokenInterceptor constructor(private val preferences: Preferences) : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {

        val accessToken = if (preferences.isUserLoggedIn)
            preferences.token
        else
            null
        val request = chain.request().newBuilder()
                .addHeader("Authorization", "$accessToken")
                .build()
        return chain.proceed(request)
    }
}